home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / freetype.zip / ttcalc16.inc < prev    next >
Text File  |  1996-09-07  |  5KB  |  251 lines

  1. {**********************************************************}
  2. {*                                                        *}
  3. {* The following routines are inline assembly, they are   *}
  4. {* thus processor and bitness specific. Replace them      *}
  5. {* with your own if you want to port the TrueType Engine  *}
  6.  
  7.  
  8. {**********************************************************}
  9. {* Four operations to convert from Motorola to Intel      *}
  10.  
  11. (*
  12.    void Do16( unsigned short* S )
  13.    {
  14.      *S = ( *S >> 8 ) | ( *S << 8 );
  15.    }
  16. *)
  17.  
  18. procedure Do16( var S ); assembler;
  19. asm
  20.   les  si, [S].dword
  21.   mov  ax, es:[si]
  22.   xchg al, ah
  23.   mov  es:[si], ax
  24. end;
  25.  
  26. (*
  27.    void Do16s( unsigned short* S, int Cnt )
  28.    {
  29.      while ( Cnt > 0 )
  30.      {
  31.        *S = ( *S >> 8 ) | ( *S << 8 );
  32.        S++;
  33.        Cnt--;
  34.      }
  35.    }
  36. *)
  37.  
  38. procedure Do16s( var S; Cnt : Int ); assembler;
  39. asm
  40.   les  si, [S].dword
  41.   mov  cx, [Cnt]     (* 'int' is 16 bit in Turbo-Pascal *)
  42.  @1:
  43.   mov  ax, es:[si]
  44.   xchg al, ah
  45.   mov  es:[si], ax
  46.   add  si, 2
  47.   dec  cx
  48.   jnz  @1
  49. end;
  50.  
  51. (*
  52.   void Do32( unsigned long* L )
  53.   {
  54.     *L = ( *L << 24 ) | ( ( *L  << 8 ) & 0x0F00 ) |
  55.          ( ( *L >> 8 ) & 0x00F0 ) | ( *L >> 24 );
  56.   }
  57. *)
  58.  
  59. procedure Do32( var L ); assembler;
  60. asm
  61.   les  si, [L]
  62.   mov  dx, es:[si].word
  63.   mov  ax, es:[si+2].word
  64.   xchg al, ah
  65.   xchg dl, dh
  66.   mov  es:[si+2].word, dx
  67.   mov  es:[si].word, ax
  68. end;
  69.  
  70. (*
  71.   void Do32s( unsigned long* L, int Cnt )
  72.   {
  73.     while ( Cnt > 0 )
  74.     {
  75.       *L = ( *L << 24 ) | ( ( *L  << 8 ) & 0x0F00 ) |
  76.            ( ( *L >> 8 ) & 0x00F0 ) | ( *L >> 24 );
  77.       L++;
  78.       Cnt--;
  79.     }
  80.   }
  81. *)
  82.  
  83. procedure Do32s( var L; Cnt : int ); assembler;
  84. asm
  85.   les  si,[L].dword
  86.   mov  cx,[Cnt]    (* 'int' is 'longint' in Virtual Pascal *)
  87.  @1:
  88.   mov  dx, es:[si].word
  89.   mov  ax, es:[si+2].word
  90.   xchg al, ah
  91.   xchg dl, dh
  92.   mov  es:[si+2].word, dx
  93.   mov  es:[si].word, ax
  94.   add  si,4
  95.   dec  cx
  96.   jnz  @1
  97. end;
  98.  
  99.  
  100.  
  101. {**********************************************************}
  102. {* Calc A*B/C with Intermediate 64 bit precision          *}
  103.  
  104. function MulDiv( A, B, C : Int32 ): Int32; assembler;
  105. var
  106.   R : Int32;
  107. asm
  108.   db $66; mov ax,[A].word
  109.   db $66; imul [B].word
  110.   db $66; idiv [C].word
  111.   db $66; mov [R].word,ax
  112.   mov dx,[R+2].word
  113. end;
  114.  
  115.  
  116.  
  117. {**********************************************************}
  118. {* 64 Bit Addition                                        *}
  119.  
  120. procedure Add64( var X, Y, Z : Int64 ); assembler;
  121. asm
  122.   les si,[X]
  123.  
  124.   mov ax,es:[ si ].word
  125.   mov dx,es:[si+2].word
  126.   mov bx,es:[si+4].word
  127.   mov cx,es:[si+6].word
  128.  
  129.   les si,[Y]
  130.   add ax,es:[ si ].word
  131.   adc dx,es:[si+2].word
  132.   add bx,es:[si+4].word
  133.   adc cx,es:[si+6].word
  134.  
  135.   les si,[Z]
  136.   mov es:[ si ].word,ax
  137.   mov es:[si+2].word,dx
  138.   mov es:[si+4].word,bx
  139.   mov es:[si+6].word,cx
  140. end;
  141.  
  142.  
  143. {**********************************************************}
  144. {* 64 Bit Substraction                                    *}
  145.  
  146. procedure Sub64( var X, Y, Z : Int64 ); assembler;
  147. asm
  148.   les si,[X]
  149.  
  150.   mov ax,es:[ si ].word
  151.   mov dx,es:[si+2].word
  152.   mov bx,es:[si+4].word
  153.   mov cx,es:[si+6].word
  154.  
  155.   les si,[Y]
  156.   sub ax,es:[ si ].word
  157.   sbb dx,es:[si+2].word
  158.   sub bx,es:[si+4].word
  159.   sbb cx,es:[si+6].word
  160.  
  161.   les si,[Z]
  162.   mov es:[ si ].word,ax
  163.   mov es:[si+2].word,dx
  164.   mov es:[si+4].word,bx
  165.   mov es:[si+6].word,cx
  166. end;
  167.  
  168.  
  169. {**********************************************************}
  170. {* Multiply two Int32 to an Int64                         *}
  171.  
  172. procedure MulTo64( X, Y : Int32; var Z : Int64 ); assembler;
  173. asm
  174.   les si,[Z]
  175.   db $66; mov ax,[X].word
  176.   db $66; imul [Y].word
  177.   db $66; mov es:[si],ax
  178.   db $66; mov es:[si+4],dx
  179. end;
  180.  
  181.  
  182. {**********************************************************}
  183. {* Divide an Int64 by an Int32                            *}
  184.  
  185. function Div64by32( var X : Int64; Y : Int32 ) : Int32; assembler;
  186. asm
  187.   les si,[X]
  188.  
  189.   db $66; mov ax,es:[si]
  190.   db $66; mov dx,es:[si+2]
  191.   db $66; idiv [Y].word
  192. end;
  193.  
  194.  
  195. {**********************************************************}
  196. {* MSB index ( return -1 for 0 )                          *}
  197.  
  198. function Order64( var Z : Int64 ) : int; assembler;
  199. asm
  200.   les si,[Z]
  201.   db $66; mov ax,es:[si]
  202.   db $66; mov dx,es:[si+4]
  203.   mov bx,63
  204.   db $66; mov cx,0; dw $8000
  205.  
  206.  @1:
  207.   db $66; test dx,cx
  208.   jnz @3
  209.   dec bx
  210.   db $66; ror cx,1
  211.   jns @1
  212.  
  213.  @2:
  214.   db $66; test ax,cx
  215.   jnz @2
  216.   dec bx
  217.   db $66; ror cx,1
  218.   jns @2
  219.  
  220.  @3:
  221.   mov ax,bx
  222. end;
  223.  
  224.  
  225. {**********************************************************}
  226. {* MSB index ( return -1 for 0 )                          *}
  227.  
  228. function Order32( Z : Int32 ) : int; assembler;
  229. asm
  230.   les si,[Z]
  231.   db $66; mov ax,es:[si]
  232.   mov bx,31
  233.   db $66; mov cx,0; dw $8000
  234.  
  235.  @1:
  236.   db $66; test ax,cx
  237.   jnz @2
  238.   dec bx
  239.   db $66; ror cx,1
  240.   jns @1
  241.  
  242.  @2:
  243.   mov ax,bx
  244. end;
  245.  
  246.  
  247.  
  248. {* End of processor specific routines                     *}
  249. {*                                                        *}
  250. {**********************************************************}
  251.